package org.dbpedia.extraction.mappings

//TODO maybe extend the list class with this? with the implicit construct...
case class MyBuffer[A] (givenList : List[A], lookAheadAndBack : Int) {
  require(lookAheadAndBack >= 0)

  def iterateOverWith(fun : (A, List[A], Int) => Unit) : Unit = {
    for (i <- givenList.indices) {
      val lowerBound = Math.max(0, i - lookAheadAndBack)
      val upperBound = Math.min(givenList.size , i + lookAheadAndBack + 1)
      val slice = givenList.slice(lowerBound, upperBound)
      val pos = if(lowerBound == 0){i} else {lookAheadAndBack}

      //apply
      fun(slice(pos), givenList.slice(lowerBound, upperBound), pos)
    }
  }
}